package study;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

/**
 * @version 1.0
 * @since:
 * @ClassName:CollectionPrintTest
 * @author: Li Jiahui
 * @date: 2021-04-22 23:15
 */
public class CollectionPrintTest {
    public static void main(String[] args) {
        Collection c1 = new ArrayList();
        c1.add("one");
        c1.add(2);
        c1.add(new Person("zhangfei", 30));
        System.out.println("c1 =" + c1);
        System.out.println("--------------------");
        Iterator iterator1 = c1.iterator();
        System.out.println(iterator1.hasNext());
        /*for (iterator.hasNext():
             ) {
             System.out.println("获取到的元素是：" + iterator.next());
        }*/
        Object obj = new ArrayList();
        while (iterator1.hasNext()){
            System.out.println(iterator1.next());
        }
        //由于迭代器在上面已经被使用过了，所以这里重新初始化一下
        //iterator1 = c1.iterator();
        StringBuilder sb1 = new StringBuilder();
        sb1.append("[");
        while (iterator1.hasNext()){
            sb1.append(obj).append("]");
        }
        if (!iterator1.hasNext()){
            sb1.append("]");
        }
        else {
            sb1.append(obj).append(",").append(" ");
        }
        System.out.println(sb1);
        iterator1 = c1.iterator();
        while (iterator1.hasNext()){
            Object obj1 = iterator1.next();
            if ("one".equals(obj1)){
                iterator1.remove();
            }
        }
        System.out.println("删除后集合中的元素有：" + c1 );
        for (Object obj1:c1){
            System.out.println(obj1);
        }
        int[] arr = new int[] {11,22,33,44,55};
        for (int i:arr) {
            System.out.println(i);
        }
        System.out.println(Arrays.toString(arr));
    }



}
